﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chess
{
    public class Knight: InterfacePiece
    { 
        Piece piece = null;
        
        public Knight(Piece Knight)
		{
			piece = Knight;
		}        
	
        public int ImageIndex
        {
            get {return (this.piece.Player.isColor == Player.Color.BLACK ? 5 : 4); }
        }             

        public void SetPosition(Moves moves)
        {
            Square square;
            square = Board.GetSquare(piece.Square.Ordinal + 33);
            if(square != null && (square.Piece == null || square.Piece.Player.isColor != piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal - 33);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor != piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal + 31);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor != piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);            

            square = Board.GetSquare(piece.Square.Ordinal - 31);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor != piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal + 18);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor != piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal - 18);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor != piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);

            square = Board.GetSquare(piece.Square.Ordinal + 14);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor != piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);
          
            square = Board.GetSquare(piece.Square.Ordinal - 14);
            if (square != null && (square.Piece == null || square.Piece.Player.isColor != piece.Player.isColor))
                moves.Add(this.piece, this.piece.Square, square, square.Piece);
        }
    }
}
